package com.huitone.smspfm.interfacz.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.huitone.smspfm.interfacz.logger.ExtLogger;
import org.springframework.data.redis.serializer.StringRedisSerializer;

import com.bin.common.utils.DateTimeUtils;
import com.bin.common.utils.StringUtils;

/**   
* @Title SMMoDealHash.java 
* @Package com.huitone.smspfm.interfacz.model 
* @Description TODO(用一句话描述该文件做什么) 
* @author ybliang   
* @date 2017年4月11日 下午5:51:44 
* @version V1.0   
*/
public class MoDealHash {
	
	private static final ExtLogger logger = ExtLogger.create(MoDealHash.class);
	
	private StringRedisSerializer serializer = new StringRedisSerializer();

	private String iSMCacheKey;
	private long iRptSnPart1;
	private long iRptSnPart2;
	private long iRptSnPart3;
	private int iSendTimes;
	private Date iLastSendTime;
	
	public Map<byte[], byte[]> getMapB() {
		Map<byte[], byte[]> map = new HashMap<>();
		map.put(serializer.serialize("ISMCacheKey"), serializer.serialize(iSMCacheKey));
		map.put(serializer.serialize("IRptSnPart1"), serializer.serialize(StringUtils.toString(iRptSnPart1)));
		map.put(serializer.serialize("IRptSnPart2"), serializer.serialize(StringUtils.toString(iRptSnPart2)));
		map.put(serializer.serialize("IRptSnPart3"), serializer.serialize(StringUtils.toString(iRptSnPart3)));
		map.put(serializer.serialize("ISendTimes"), serializer.serialize(StringUtils.toString(iSendTimes)));
		map.put(serializer.serialize("ILastSendTime"), serializer.serialize(DateTimeUtils.dateToStr2(iLastSendTime)));
		return map;
	}
	
	public Map<Object, Object> getMap() {
		Map<Object, Object> map = new HashMap<>();
		map.put("ISMCacheKey", iSMCacheKey);
		map.put("IRptSnPart1", StringUtils.toString(iRptSnPart1));
		map.put("IRptSnPart2", StringUtils.toString(iRptSnPart2));
		map.put("IRptSnPart3", StringUtils.toString(iRptSnPart3));
		map.put("ISendTimes", StringUtils.toString(iSendTimes));
		map.put("ILastSendTime", DateTimeUtils.dateToStr2(iLastSendTime));
		return map;
	}
	
	public static List<Object> getColumns() {
		List<Object> list = new ArrayList<>();
		list.add("ISMCacheKey");
		list.add("IRptSnPart1");
		list.add("IRptSnPart2");
		list.add("IRptSnPart3");
		list.add("ISendTimes");
		list.add("ILastSendTime");
		return list;
	}
	
	public static MoDealHash parse(List<Object> list) {
		MoDealHash entity = new MoDealHash();
		try {
			entity.setiSMCacheKey(StringUtils.toString(list.get(0)));
			entity.setiRptSnPart1(StringUtils.tolong(list.get(1)));
			entity.setiRptSnPart2(StringUtils.tolong(list.get(2)));
			entity.setiRptSnPart3(StringUtils.tolong(list.get(3)));
			entity.setiSendTimes(StringUtils.toInteger(list.get(4)));
			entity.setiLastSendTime(DateTimeUtils.strToDate(StringUtils.toString(list.get(5)), "yyyyMMddHHmmss"));
		} catch (Exception e) {
			logger.error("MoDealHash短信信息读取时发生异常", e);
		}
		
		return entity;
	}
	
	public static MoDealHash parseStr(List<String> list) {
		MoDealHash entity = new MoDealHash();
		try {
			entity.setiSMCacheKey(StringUtils.toString(list.get(0)));
			entity.setiRptSnPart1(StringUtils.tolong(list.get(1)));
			entity.setiRptSnPart2(StringUtils.tolong(list.get(2)));
			entity.setiRptSnPart3(StringUtils.tolong(list.get(3)));
			entity.setiSendTimes(StringUtils.toInteger(list.get(4)));
			entity.setiLastSendTime(DateTimeUtils.strToDate(StringUtils.toString(list.get(5)), "yyyyMMddHHmmss"));
		} catch (Exception e) {
			logger.error("MoDealHash短信信息读取时发生异常", e);
		}
		
		return entity;
	}
	
	public boolean isExists() {
		return !StringUtils.isEmpty(iSMCacheKey);
	}
	
	public String getSerialNo() {
		StringBuffer buffer = new StringBuffer();
		buffer.append(iRptSnPart1);
		buffer.append(iRptSnPart2);
		buffer.append(iRptSnPart3);
		return buffer.toString(); 
	}

	public String getiSMCacheKey() {
		return iSMCacheKey;
	}

	public void setiSMCacheKey(String iSMCacheKey) {
		this.iSMCacheKey = iSMCacheKey;
	}

	public long getiRptSnPart1() {
		return iRptSnPart1;
	}

	public void setiRptSnPart1(long iRptSnPart1) {
		this.iRptSnPart1 = iRptSnPart1;
	}

	public long getiRptSnPart2() {
		return iRptSnPart2;
	}

	public void setiRptSnPart2(long iRptSnPart2) {
		this.iRptSnPart2 = iRptSnPart2;
	}

	public long getiRptSnPart3() {
		return iRptSnPart3;
	}

	public void setiRptSnPart3(long iRptSnPart3) {
		this.iRptSnPart3 = iRptSnPart3;
	}

	public int getiSendTimes() {
		return iSendTimes;
	}

	public void setiSendTimes(int iSendTimes) {
		this.iSendTimes = iSendTimes;
	}
	
	public Date getiLastSendTime() {
		return iLastSendTime;
	}

	public void setiLastSendTime(Date iLastSendTime) {
		this.iLastSendTime = iLastSendTime;
	}
}
